﻿/*
Copyright (c) 2010 Lance Ward
This software is licensed under the MIT license, except where otherwise noted.
For complete license details, refer to license.txt
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using ADNLib;

namespace ADNCanvas
{
	//handles drawing of shapes with multiple points that are released by double-click
	public class ToolBezier : Tool
	{
		public ToolBezier(DrawingToolType toolType)
		{
			this.toolType = toolType;
		}

		public ToolBezier() { }

		public override void MouseDown(PointF location, System.Windows.Forms.MouseButtons button, int clicks)
		{
			if (currentShape == null)
			{
				CreateShape(location);
				currentShape.AppendPoint(location, true);
			}
			else 
			{
                if (clicks < 2) //don't use if the second click of a double-click
                {
                    currentShape.AppendPoint(location, false);
                }
			}
		}

		public override void MouseMove(PointF location, System.Windows.Forms.MouseButtons button, int clicks)
		{
			if (currentShape != null)
			{
				currentShape.AppendPoint(location, true);
			}
		}

		public override void MouseUp(PointF location, System.Windows.Forms.MouseButtons button, int clicks)
		{
			
		}

		public override void MouseDoubleClick(PointF location, System.Windows.Forms.MouseButtons button, int clicks)
		{
			//currentShape.AppendPoint(location, false); //already registered a click, no need to add another
			OnShapeComplete(true);
			OnToolComplete(true);

			currentShape = null;
		}

		public override System.Windows.Forms.Cursor GetToolCursor()
		{
			return Cursors.Cross;
		}

		private void CreateShape(PointF startPoint)
		{
			switch (ToolType)
			{
				case DrawingToolType.Bezier:
					currentShape = new ShapeBezier();
					break;
			}

			currentShape.AppendPoint(startPoint, true);
			currentShape.FillColor = defaultFill.Clone();
			currentShape.LineColor = defaultLine.Clone();
		}
	}
}
